home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Mac Game Programming Gurus / TricksOfTheMacGameProgrammingGurus.iso / Demos / Tools / AppMaker / Examples / pre-built AMReminder / PowerPlant / CAMReminderData.cp < prev    next >
Encoding:
Text File  |  1994-11-03  |  3.6 KB  |  175 lines  |  [TEXT/MMCC]

  1. // CAMReminderData.cp -- document data
  2. // Created 01/01/95 12:01 PM by AppMaker
  3.  
  4. // The purpose of the Data module is to shield the rest of your application
  5. // from your internal data structures and the representation of your files.
  6. // The Data module provides an abstract interface to the contents of your files.
  7.  
  8. #include "CAMReminderData.h"
  9.  
  10. #include <LFileStream.h>
  11.  
  12. // ---------------------------------------------------------------------------
  13. //        • CAMReminderData - for New
  14. // ---------------------------------------------------------------------------
  15.  
  16. CAMReminderData::CAMReminderData()
  17.         :LBroadcaster()
  18. {
  19.     mFile = nil;
  20.     CreateData();
  21. }
  22.  
  23. // ---------------------------------------------------------------------------
  24. //        • CAMReminderData - for Open
  25. // ---------------------------------------------------------------------------
  26.  
  27. CAMReminderData::CAMReminderData    (FSSpec        *inMacFSSpec)
  28.         :LBroadcaster()
  29. {
  30.     mFile = OpenFile(inMacFSSpec);
  31.     ReadData();
  32. }
  33.  
  34. // ---------------------------------------------------------------------------
  35. //        • ~CAMReminderData
  36. // ---------------------------------------------------------------------------
  37. //    Destructor
  38. //
  39.  
  40. CAMReminderData::~CAMReminderData()
  41. {
  42.     CloseFile();
  43. }
  44.  
  45. //----------
  46. Boolean    CAMReminderData::IsDirty()
  47. {
  48.     return mDirty;
  49. }
  50.  
  51. //----------
  52. void    CAMReminderData::DoSave()
  53. {
  54.     WriteData(mFile);
  55. }
  56.  
  57. //----------
  58. void    CAMReminderData::DoSaveAs    (FSSpec        *inMacFSSpec)
  59. {
  60.     LFileStream        *file;
  61.  
  62.     file = CreateFile(inMacFSSpec);
  63.     if (file != nil) {
  64.         WriteData(file);
  65.         CloseFile();    // old file
  66.         mFile = file;
  67.     }
  68. }
  69.  
  70. //----------
  71. void    CAMReminderData::DoRevert()
  72. {
  73.     DisposeData();
  74.     if (mFile != nil) {
  75.         ReadData();
  76.     }
  77. }
  78.  
  79. //----------
  80. void    CAMReminderData::CloseFile()
  81. {
  82.     if (mFile != nil) {
  83.         delete mFile;
  84.         mFile = nil;
  85.     }
  86. }
  87.  
  88. //----------
  89. // CreateFile is called in two situations:
  90. // 1. To Save a new untitled document
  91. // 2. To SaveAs to a new file
  92.  
  93. LFileStream        *CAMReminderData::CreateFile    (FSSpec        *inMacFSSpec)
  94. {
  95.     LFileStream        *file = new LFileStream(*inMacFSSpec);
  96.  
  97.     file->CreateNewDataFile(kSignature, kFileType);
  98.     file->OpenDataFork(fsRdWrPerm);
  99.  
  100.     return file;
  101. }
  102.  
  103. //----------
  104. LFileStream        *CAMReminderData::OpenFile        (FSSpec        *inMacFSSpec)
  105. {
  106.     LFileStream        *file = new LFileStream(*inMacFSSpec);
  107.  
  108.     file->OpenDataFork(fsRdWrPerm);
  109.  
  110.     return file;
  111. }
  112.  
  113. // The next few methods are for transferring data between the
  114. // data file and your internal data structures, and for disposing
  115. // your data structures. They are called by Open, Close, etc.
  116. // Replace their bodies with whatever is suitable for your application
  117.  
  118. // define internal data structures to describe the file format:
  119.  
  120. //----------
  121. typedef struct
  122. {
  123.     int            stuff;
  124.  
  125. } AMReminderData;
  126.  
  127. //----------
  128. void    CAMReminderData::CreateData()
  129. {
  130.     // initialize your data structures
  131. }
  132.  
  133. //----------
  134. void    CAMReminderData::DisposeData()
  135. {
  136.     // delete your data structures
  137.  
  138.     mDirty = false;
  139. }
  140.  
  141. //----------
  142. void    CAMReminderData::ReadData()
  143. {
  144.     // read all or part of the file into your data structures
  145. }
  146.  
  147. //----------
  148. // WriteData is called in two situations:
  149. // 1. To Save the current document
  150. // 2. To SaveAs to a new file
  151.  
  152. void    CAMReminderData::WriteData        (LFileStream    *file)
  153. {
  154.     // write from your data structures to the file
  155.  
  156.     mDirty = false;
  157. }
  158.  
  159. // The remaining methods are for accessing your data as logical chunks.
  160. // These are just models for your own accessor functions;
  161. // they aren't called by any AppMaker-generated code.
  162. // Replace them with whatever is suitable for your application.
  163.  
  164. //----------
  165. void    CAMReminderData::GetStuff    (void    *stuff)
  166. {
  167. }
  168.  
  169. //----------
  170. void    CAMReminderData::SetStuff    (void    *stuff)
  171. {
  172. }
  173.  
  174. // AMReminderData.cp
  175.